package org.example.一对多.dao;

import org.example.一对多.bean.DeptInfo;
import org.example.面向对象.db.DBManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DeptInfoDAO {
    private Connection conn;
    private PreparedStatement ps;
    private ResultSet rs;

    public DeptInfo findDeptByid(int deptNo){
        DeptInfo di = new DeptInfo();
        String sql = "select * from dept where deptno=?";
        conn = DBManager.getConnection();
       try {
           ps = conn.prepareStatement(sql);
           ps.setInt(1,deptNo);
           rs = ps.executeQuery();
           while (rs.next()){
               di.setDeptNo(rs.getInt(1));
               di.setDname(rs.getString(2));
               di.setLoc(rs.getString(3));
           }
       }catch (SQLException e){
           System.out.println(e.getMessage());
       }
        return di;
    }
}
